import 'package:flutter/material.dart';
import 'package:zy_pos_demo/resources/res.dart';

class EdgeStateEditText extends StatefulWidget {
  EdgeStateEditText(
      {this.hint,
      this.image,
      this.hide = false,
      this.controller})
      : super();
  final String hint;
  final String image;
  final bool hide;
  TextEditingController controller;

  @override
  _EdgeStateEditTextState createState() => _EdgeStateEditTextState();
}

class _EdgeStateEditTextState extends State<EdgeStateEditText> {
  final FocusNode fn = FocusNode();
  String hint;
  String icon;
  bool hide;

  TextEditingController _controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    hint = widget.hint;
    icon = widget.image;
    hide = widget.hide;
    _controller = widget.controller;
    fn.addListener(() => setState(() => {}));
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 55,
      width: double.infinity,
      alignment: Alignment.center,
      child: TextField(
        autofocus: false,
        focusNode: fn,
        controller: _controller,
        obscureText: hide,
        style: TextStyle(
          fontSize: 20.0,
          color: AppColors.BLACK_3,
        ),
        decoration: InputDecoration(
          border: InputBorder.none,
          labelText: (fn.hasFocus || _controller.text.length > 0) ? null : hint,
          prefixIcon: UnconstrainedBox(
            child: Image.asset(
              icon,
              width: 20,
              height: 20,
            ),
          ),
        ),
      ),
      decoration: BoxDecoration(
        border: Border.all(
          color: fn.hasFocus ? AppColors.YELLOW_FDB : AppColors.GREY_C0,
          width: 1.0,
          style: BorderStyle.solid,
        ),
        color: AppColors.GREY_F3,
        borderRadius: BorderRadius.all(Radius.circular(2)),
      ),
    );
  }
}
